#include <ostream>
#include <unordered_map>
#include "RtspMethod.h"

namespace rtsp {

struct EnumClassHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};

std::unordered_map<Method, std::string, EnumClassHash> MethodTable = {
        {Method::kUnknown,           "Unknown"},
        {Method::kOption,            "OPTION"},
        {Method::kDescribe,          "DESCRIBE"},
        {Method::kAnnounce,          "ANNOUNCE"},
        {Method::kSetup,             "SETUP"},
        {Method::kPlay,              "PLAY"},
        {Method::kPause,             "PAUSE"},
        {Method::kTearDown,          "TEARDOWN"},
        {Method::kGetParameter,      "GET_PARAMETER"},
        {Method::kSetParameter,      "SET_PARAMETER"},
        {Method::kRedirect,          "REDIRECT"},
        {Method::kRecord,            "RECORD"}
};

std::string methodToString(Method method)
{
    auto iter = MethodTable.find(method);
    if(iter != MethodTable.end())
    {
        return iter->second;
    }

    return "Unknown";
}

Method stringToMethod(const std::string& s)
{
    auto iter = MethodTable.begin();
    for(;iter != MethodTable.end(); iter++){
        if(iter->second == s){
            return iter->first;
        }
    }
    return Method::kUnknown;
}


std::ostream& operator<<(std::ostream& os, Method method)
{
    return os << methodToString(method);
}

} // rtsp



